function WaiMai() {
}

// Global function清除tips
WaiMai.ClearTips = function (tipID) {
    var tip = document.getElementById(tipID);
    tip.innerHTML = "";
}
// 获得随机数
WaiMai.GetRandomCode = function () {
    var authCode = Math.random() * 10000 + 1000 + "";
    authCode = authCode.substring(0, 4);
    return authCode;
}

// User center function
WaiMai.UserCenter = function () { }
// 邮箱验证
WaiMai.UserCenter.IsRightEmailFormat = function (email) {
    if (/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(email)) {
        return true;
    } else {
        return false;
    }
}

// 电话号码验证
WaiMai.UserCenter.IsRightPhoneNumFormat = function (phoneNum) {
    if (phoneNum.length == 11) {
        return true;
    } else {
        return false;
    }
}

//购买商品
function buy(userName,goodsId){
	if(userName=="null"){
		window.location.href="logReg.jsp?action=login";
	}else{
		$.ajax({
			type : "POST",
			url : "servlet/CartServlet",
			data : "action=add&goodsId="+goodsId+"&userName=" +userName,
			success : function(result) {
				var result= result.trim();
				if(result=="success"){
					window.location.href="shopCart.jsp";
				}else{
				}
			}
		});
	}
}
//团购商品
function tbuy(userName,goodsId){
	if(userName=="null"){
		window.location.href="logReg.jsp?action=login";
	}else{
		$.ajax({
			type : "POST",
			url : "servlet/TCartServlet",
			data : "action=add&goodsId="+goodsId+"&userName=" +userName,
			success : function(result) {
				var result= result.trim();
				if(result=="success"){
					window.location.href="tgConfirm.jsp";
				}else{
				}
			}
		});
	}
}